﻿using System;
using System.Linq;

namespace N2.ComponentModel
{
	using Details;
	
	public class DetailCollectionCollectionEditor : DetailCollectionEditor
	{
		#region Constructors

		public DetailCollectionCollectionEditor(Type type) : base(type) { }

		#endregion Constructors

		protected override object[] GetItems(object editValue)
		{
			var _collection = editValue as DetailCollection;

			return
				null == _collection
					? new object[0]
					: _collection.Details.ToArray();
		}

		protected override object SetItems(object editValue, object[] value)
		{
			var _collection = editValue as DetailCollection;
			
			_collection.Clear();
			_collection.AddRange(value.Cast<ContentDetail>());
			
			return _collection;
		}
	}
}
